import {
	defineStore
} from 'pinia';
import {
	getUserInfoApi
} from '../api/login';

export const useUserStore = defineStore('user', {
	state: () => {
		return {
			// 保存当前登录的用户信息，初始为空
			userInfo: null,

		}
	},
	getters: {
		userId(state) {
			return state.userInfo?._id;
		}
	},
	actions: {
		async getUserInfoAction() {
			const res = await getUserInfoApi();
			if (res.code == 200) {
				// 将请求结果保存到state的userInfo中
				this.userInfo = res.data;

			}
		},

		// 查询家庭成员
		async accSearchTeam() {
			const res = await searchMemberApi({
				ownId: userInfoId
			})
			if (res.code == 200) {
				this.familyTeam = res.data
				console.log(res);
			}
		}

	}
})